package week6.homework;
//************************************************************************************************************
//  AccountCollection.java       Author:Duanzhixuan
//***********************************************************************************************************
import week6.homework.Account;
import java.text.NumberFormat;
import java.util.Scanner;
public class AccountCollection
{
private Account[] collection;
private int count;
public AccountCollection()
{ 
  collection = new Account[30];
   count=0;
}
public void addAccount(String owner, long account, double initial)
{
  
   if (count < collection.length)
       {
           collection[count] = new Account(owner, account, initial);
          count++;;
}//添加账户
}
public String toString()
{
  String result="---------------------------------------";
 for(int f=0;f<30;f++)
{ if (collection[f] !=null)
result+=collection[f].toString()+"\n";}

return result;
}//打印出所有账户信息
public void addInteret()
{ 
   
      int b = 0;
      while(b < collection.length)
      {
          if (collection[b] != null)
          {
              collection[b].addInterest();
          }
          b++;
     
    
}
}//给所有账户加上利息   
public void outBalance(String owner, long account, double intion)
{
  for(int a=0;a<30;a++)
  if (collection[a] != null)
  if (collection[a].getName().equals(owner)&&collection[a].getNumber()==account)
  if (collection[a].getNumber()>intion)
  collection[a].withdraw(intion);
 //根据输入的账户和用户名进行取款，并且判断取款金额是否大于账户余额。
}
public void inBalance(String owner,long account, double intion)
{
  for(int c=0;c<30;c++)
    if (collection[c] != null)
    if (collection[c].getName().equals(owner)&&collection[c].getNumber()==account)
    collection[c].deposit(intion);
   
}//根据输入的账户和用户名进行存款。
}
